import math


def calculationQ(a, m, density, alpha):
    '''
        方法：计算压煤量
        参数：A——煤柱平均面积，m²
            m——煤层厚度，m
            density——煤层质量密度，t/m²
            alpha——煤层倾角，°
        return：Q——压煤量
    '''
    Q = a * m * density / math.cos(alpha)
    return Q


if __name__ == '__main__':
    f = open("压煤量.txt", "r")
    w = open("压煤量_结果.txt", "w")
    field = f.readline()
    print(field)
    if field == "a m dens alp\n":
        print("字段相同")
        while field:
            print(field)
            field = f.readline()
            if field == "": break
            data = field.split(" ")
            a = float(data[0])
            m = float(data[1])
            density = float(data[2])
            alpha = float(data[3])
            # print(alpha)
            Q = calculationQ(a, m, density, alpha)  # 开始计算Q
            write = str(a) + " " + str(m) + " " + str(density) + " " + str(alpha) + " " + str(Q)+"\n"
            w.write(write)
    else:
        print("请检查您的参数顺序是否为a m dens alp")
    w.flush()
    w.close()
    f.close()
